requireJS(['constant', 'site', 'handlebars'], function (Constant, site, Handlebars) {

    var seriesAll = [];
    var timeAll = [];
    var legendAll = [];

    var url = {
        personalStatistic: "manager/personalStatistic.do",
        personalSourceStatistic: "manager/personalSourceStatistic.do",
        particularYear: "manager/particularYear.do",
        selectSecondDepartment: "manager/selectSecondDepartment.do",
        personalSourceStatistic: "manager/personalSourceStatistic.do",
        applyTermStatistic: "manager/applyTermStatistic.do",
        personalCityStatistic: "manager/personalCityStatistic.do",
        personalOrderStateStatistic: "manager/personalOrderStateStatistic.do",
        allPersonalOrderStateStatistic: "manager/allPersonalOrderStateStatistic.do",
        loanTypeStatistic: "manager/loanTypeStatistic.do",

        exportPersonalStatistic: "manager/exportPersonalStatistic.do"
    };

    //所有初始化
    (function init() {
        //初始化选择年份
        /*site.send({
            url: url.particularYear,
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == '1') {
                    var source = $("#year_list_tpl").html();
                    var template = Handlebars.compile(source);
                    var html = template(data.content);
                    $('#year_list').append(html);
                } else {
                    Constant.fn.Message('F', data.msg);
                }
            }
        })*/

        //初始化分公司
        site.send({
            url: url.selectSecondDepartment,
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == '1') {
                    var source = $("#department_list_tpl").html();
                    var template = Handlebars.compile(source);
                    var html = template(data.content);
                    $('#department_list').append(html);
                } else {
                    Constant.fn.Message('F', data.msg);
                }
            }
        })
    })();

    //客户来源
    function clientCom(clientCf) {
        var clientC = []
        // $_fn.ajaxPost('manager/personalSourceStatistic.do',$scope.param,function(data) {
        clientCf.forEach(function (ele, i) {
            var obj = {
                name: ele.type_name,
                value: ele.type_num
            };
            clientC.push(obj)
        })

        // 使用
        require(
            [
                'echarts',
                'echarts/chart/pie' // 使用柱状图就加载bar模块，按需加载
            ],
            function (ec) {
                if (!document.getElementById('echar5')) {
                    return;
                }
                var myChart = ec.init(document.getElementById('echar5'))
                var option4 = {
                    noDataLoadingOption: {
                        text: '暂无数据',//没有数据时显示的文字
                        effect: 'bubble',//loading效果，此为气泡，还有'spin' | 'bar' | 'ring' | 'whirling' | 'dynamicLine' | 'bubble'
                        effectOption: {
                            effect: {
                                n: 0 //气泡个数为0
                            }
                        },
                        textStyle: { //没有数据时显示的文字的样式
                            fontSize: 16,
                            fontWeight: 'bold'
                        }
                    },
                    title: {},
                    tooltip: {
                        trigger: 'item',
                        formatter: '{a} <br/>{b} : {c} ({d}%)',
                        showDelay: 0,
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: clientC.name ? clientC.name : 100
                    },
                    series: [
                        {
                            name: '客户来源',
                            type: 'pie',
                            radius: '60%',
                            center: ['50%', '50%'],
                            data: clientC,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ],
                    color: ['rgb(194,53,49)', 'rgb(47,69,84)', 'rgb(97,160,168)', 'rgb(212,130,101)', 'rgb(145,199,174)',
                        'rgb(116,159,131)']
                }
                myChart.setOption(option4)
            })
        // })
    }

    //借款期限
    function loanDl(loanded) {
        var loanDedline = []

        loanded.forEach(function (ele, i) {
            var obj = {
                name: ele.type_name,
                value: ele.type_num
            }
            loanDedline.push(obj);
        })

        require(
            [
                'echarts',
                'echarts/chart/pie' // 使用柱状图就加载bar模块，按需加载
            ],
            function (ec) {
                if (!document.getElementById('echar6')) {
                    return;
                }
                var myChart = ec.init(document.getElementById('echar6'))
                var option4 = {
                    noDataLoadingOption: {
                        text: '暂无数据',//没有数据时显示的文字
                        effect: 'bubble',//loading效果，此为气泡，还有'spin' | 'bar' | 'ring' | 'whirling' | 'dynamicLine' | 'bubble'
                        effectOption: {
                            effect: {
                                n: 0 //气泡个数为0
                            }
                        },
                        textStyle: { //没有数据时显示的文字的样式
                            fontSize: 16,
                            fontWeight: 'bold'
                        }
                    },
                    title: {},
                    tooltip: {
                        trigger: 'item',
                        formatter: '{a} <br/>{b} : {c} ({d}%)',
                        showDelay: 0,
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: loanDedline.name ? loanDedline.name : 100
                    },
                    series: [
                        {
                            name: '客户来源',
                            type: 'pie',
                            radius: '60%',
                            center: ['50%', '50%'],
                            data: loanDedline,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ],
                    color: ['rgb(194,53,49)', 'rgb(47,69,84)', 'rgb(97,160,168)', 'rgb(212,130,101)', 'rgb(145,199,174)',
                        'rgb(116,159,131)']
                }
                myChart.setOption(option4)
            })
        // })
    }

    //客户区域
    function clientPosi(clientA) {

        var client = []

        clientA.forEach(function (ele, i) {
            var obj = {}

            if (ele.typeName != 0) {
                obj.name = ele.type_name
            }
            if (ele.typeNum != 0) {
                obj.value = ele.type_num
            }
            client.push(obj)

        })
        // 使用
        // 路径配置
        /*require.config({
            paths: {
                echarts: 'http://echarts.baidu.com/build/dist'
            }
        });*/
        require(
            [
                'echarts',
                'echarts/chart/pie' // 使用柱状图就加载bar模块，按需加载
            ],
            function (ec) {
                if (!document.getElementById('echar2')) {
                    return;
                }
                var myChart = ec.init(document.getElementById('echar2'))
                var option2 = {
                    noDataLoadingOption: {
                        text: '暂无数据',//没有数据时显示的文字
                        effect: 'bubble',//loading效果，此为气泡，还有'spin' | 'bar' | 'ring' | 'whirling' | 'dynamicLine' | 'bubble'
                        effectOption: {
                            effect: {
                                n: 0 //气泡个数为0
                            }
                        },
                        textStyle: { //没有数据时显示的文字的样式
                            fontSize: 16,
                            fontWeight: 'bold'
                        }
                    },
                    title: {},
                    tooltip: {
                        trigger: 'item',
                        formatter: '{a} <br/>{b} : {c} ({d}%)',
                        showDelay: 0,
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: client.name ? client.name : 100
                    },
                    series: [
                        {
                            name: '客户区域',
                            type: 'pie',
                            radius: '60%',
                            center: ['50%', '50%'],
                            data: client,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ],
                    color: ['rgb(194,53,49)', 'rgb(47,69,84)', 'rgb(97,160,168)', 'rgb(212,130,101)', 'rgb(145,199,174)',
                        'rgb(116,159,131)']

                }
                myChart.setOption(option2)


            })
        // })
    }


    //客户订单
    function clientOd(clientord) {
        var clientOrder = [];
        clientord.forEach(function (ele, i) {

            var obj = {}
            if (ele.typeName != 0) {
                obj.name = ele.typeName
            }
            if (ele.typeRadio != 0) {
                obj.value = ele.typeNum
            }
            clientOrder.push(obj)
        })


        // 使用
        require(
            [
                'echarts',
                'echarts/chart/pie' // 使用柱状图就加载bar模块，按需加载
            ],
            function (ec) {
                if (!document.getElementById('echar3')) {
                    return;
                }
                var myChart = ec.init(document.getElementById('echar3'))
                var option2 = {
                    noDataLoadingOption: {
                        text: '暂无数据',//没有数据时显示的文字
                        effect: 'bubble',//loading效果，此为气泡，还有'spin' | 'bar' | 'ring' | 'whirling' | 'dynamicLine' | 'bubble'
                        effectOption: {
                            effect: {
                                n: 0 //气泡个数为0
                            }
                        },
                        textStyle: { //没有数据时显示的文字的样式
                            fontSize: 16,
                            fontWeight: 'bold'
                        }
                    },
                    title: {},
                    tooltip: {
                        trigger: 'item',
                        formatter: '{a} <br/>{b} : {c} ({d}%)',
                        showDelay: 0,
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: clientOrder.name ? clientOrder.name : 100
                    },
                    series: [
                        {
                            name: '客户订单',
                            type: 'pie',
                            radius: '60%',
                            center: ['50%', '50%'],
                            data: clientOrder,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ],
                    color: ['rgb(194,53,49)', 'rgb(47,69,84)', 'rgb(97,160,168)', 'rgb(212,130,101)', 'rgb(145,199,174)',
                        'rgb(116,159,131)']
                }
                myChart.setOption(option2)
            })
        // })
    }

    // 贷款类型
    function loanTy(loanType) {
        var loanT = [];
        $(".ech1").hide();


        loanType.forEach(function (ele) {

            var obj = {}
            if (ele.typeName != 0) {
                obj.name = ele.type_name
            }
            if (ele.typeNum != 0) {
                obj.value = ele.type_num
            }
            loanT.push(obj)

        })

        var dataDefault = 100
        window.devicePixelRatio = 2;


        // 使用
        require(
            [
                'echarts',
                'echarts/chart/pie' // 使用柱状图就加载bar模块，按需加载
            ],
            function (ec) {
                if (!document.getElementById('echar1')) {
                    return;
                }
                var myChart = ec.init(document.getElementById('echar1'))
                var option1 = {
                    noDataLoadingOption: {
                        text: '暂无数据',//没有数据时显示的文字
                        effect: 'bubble',//loading效果，此为气泡，还有'spin' | 'bar' | 'ring' | 'whirling' | 'dynamicLine' | 'bubble'
                        effectOption: {
                            effect: {
                                n: 0 //气泡个数为0
                            }
                        },
                        textStyle: { //没有数据时显示的文字的样式
                            fontSize: 16,
                            fontWeight: 'bold'
                        }
                    },
                    title: {},
                    tooltip: {
                        trigger: 'item',
                        formatter: '{a} <br/>{b} : {c} ({d}%)',
                        showDelay: 0,
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: loanT.name ? loanT.name : dataDefault,
                    },
                    series: [
                        {
                            name: '贷款类型',
                            type: 'pie',
                            radius: '60%',
                            center: ['50%', '50%'],
                            data: loanT,
                            hoverAnimation: true,
                            stillShowZeroSum: true,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowOffsetY: 10,
                                    shadowColor: 'rgba(0, 0, 0, 0.1)',
                                }
                            },
                        }
                    ],
                    color: ['rgb(194,53,49)', 'rgb(47,69,84)', 'rgb(97,160,168)', 'rgb(212,130,101)', 'rgb(145,199,174)',
                        'rgb(116,159,131)'],
                }


                myChart.setOption(option1)

            }
        )
        // })
    }

    var echar_fun = function (e) {
        // 路径配置
        /*requirejs.config({
            paths: {
                echarts: baseUrlStr + 'static/plugins/echarts'
            }
        });*/

        // 使用
        require(
            [
                'echarts',
                'echarts/chart/line',//需要加载line模块
                'echarts/chart/bar' // 使用柱状图就加载bar模块，按需加载
            ],
            function (ec) {
                // 基于准备好的dom，初始化echarts图表
                if (!document.getElementById('echartList-' + e)) {
                    return;
                }
                var myChart = ec.init(document.getElementById('echartList-' + e));

                /*var option = {
                    title: {
                        x: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        showDelay: 0,
                        formatter: function (params) {
                            var colorList = [
                                '#C1232B', '#B5C334', '#FCCE10', '#E87C25', '#27727B',
                                '#FE8463', '#9BCA63', '#FAD860', '#F3A43B', '#60C0DD',
                                '#D7504B', '#C6E579', '#F4E001', '#F0805A', '#26C0C0'
                            ]
                            var color = colorList[params.dataIndex];//图例颜色
                            var htmlStr = '<div>';
                            htmlStr += params.seriesName + '<br/>';//x轴的名称
                            //为了保证和原来的效果一样，这里自己实现了一个点的效果
                            htmlStr += '<span style="margin-right:5px;display:inline-block;width:10px;height:10px;border-radius:5px;background-color:' + color + ';"></span>';
                            //添加一个汉字，这里你可以格式你的数字或者自定义文本内容
                            htmlStr += params.name + '：' + params.value + '';
                            htmlStr += '</div>';
                            return htmlStr;
                        }
                    },

                    grid: {
                        borderWidth: 0,
                        y2: 60,
                        right: '5%',
                        left: '5%',

                    },
                    xAxis: [
                        {
                            type: 'category',
                            show: true,
                            data: typeNameData,
                            axisLine: {
                                show: true,
                                lineStyle: {
                                    color: '#000',
                                }
                            },
                            splitLine: {
                                show: false
                            },
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value',
                            show: true,
                            axisLine: {
                                show: true,
                                lineStyle: {
                                    color: '#000',
                                }
                            },

                        }
                    ],
                    series: series

                }*/
                var option = {
                    title: {
                        x: 'center'
                    },
                    /*tooltip: {
                        trigger: 'item',
                        showDelay: 0,
                        formatter: function (params) {
                            var colorList = [
                                '#C1232B', '#B5C334', '#FCCE10', '#E87C25', '#27727B',
                                '#FE8463', '#9BCA63', '#FAD860', '#F3A43B', '#60C0DD',
                                '#D7504B', '#C6E579', '#F4E001', '#F0805A', '#26C0C0'
                            ]
                            var color = colorList[params.dataIndex];//图例颜色
                            var htmlStr = '<div>';
                            htmlStr += params.seriesName + '<br/>';//x轴的名称
                            //为了保证和原来的效果一样，这里自己实现了一个点的效果
                            htmlStr += '<span style="margin-right:5px;display:inline-block;width:10px;height:10px;border-radius:5px;background-color:' + color + ';"></span>';
                            //添加一个汉字，这里你可以格式你的数字或者自定义文本内容
                            htmlStr += params.name + '：' + params.value + '';
                            htmlStr += '</div>';
                            return htmlStr;
                        }
                    },*/
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: legendAll[e]
                    },
                    /*legend: {
                        data: ['最高气温', '最低气温']
                    },*/
                    toolbox: {
                        show: true,
                        feature: {
                            mark: {show: true},
                            dataView: {show: true, readOnly: false},
                            magicType: {show: true, type: ['line', 'bar', 'stack', 'tiled']},
                            restore: {show: true},
                            saveAsImage: {show: true}
                        }
                    },
                    calculable: true,
                    xAxis: [
                        {
                            type: 'category',
                            boundaryGap: false,
                            data: timeAll[e]
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value',
                            /*axisLabel: {
                                formatter: '{value} °C'
                            },*/
                        }
                    ],
                    /*series: [
                        {
                            name: '产品订单状态统计',
                            type: 'line',
                            /!*data: [11, 11, 15, 13, 12, 13, 10],*!/
                            /!*markPoint: {
                                data: [
                                    {type: 'max', name: '最大值'},
                                    {type: 'min', name: '最小值'}
                                ]
                            },*!/
                            /!*markLine: {
                                data: [
                                    {type: 'average', name: '平均值'}
                                ]
                            }*!/
                            "data": typeNum,
                        },
                        /!*{
                            name: '最低气温',
                            type: 'line',
                            data: [1, -2, 2, 5, 3, 2, 0],
                            markPoint: {
                                data: [
                                    {name: '周最低', value: -2, xAxis: 1, yAxis: -1.5}
                                ]
                            },
                            markLine: {
                                data: [
                                    {type: 'average', name: '平均值'}
                                ]
                            }
                        }*!/
                    ]*/
                    series: seriesAll[e]
                };
                // 为echarts对象加载数据
                myChart.setOption(option);

                window.onresize = myChart.resize;

            }
        );
    }


    // 圆柱表
    /*function bar_bottom(typeName, typeRatio, typeNum) {
        // 路径配置
        require.config({
            paths: {
                echarts: baseUrlStr + 'static/plugins/echarts'
            }
        });

        // 使用
        require(
            [
                'echarts',
                'echarts/chart/line',//需要加载line模块
                'echarts/chart/bar' // 使用柱状图就加载bar模块，按需加载
            ],
            function (ec) {
                if (!document.getElementById('echar7')) {
                    return;
                }
                // 基于准备好的dom，初始化echarts图表
                var myChart = ec.init(document.getElementById('echar7'));

                var option = {
                    title: {
                        x: 'center'
                    },
                    noDataLoadingOption: {
                        text: '暂无数据',//没有数据时显示的文字
                        effect: 'bubble',//loading效果，此为气泡，还有'spin' | 'bar' | 'ring' | 'whirling' | 'dynamicLine' | 'bubble'
                        effectOption: {
                            effect: {
                                n: 0 //气泡个数为0
                            }
                        },
                        textStyle: { //没有数据时显示的文字的样式
                            fontSize: 16,
                            fontWeight: 'bold'
                        }
                    },
                    tooltip: {
                        trigger: 'item',
                        showDelay: 0,
                        backgroundColor: 'rgba(0,0,0,0.5)',
                        formatter: function (params) {
                            var colorList = [
                                '#C1232B', '#B5C334', '#FCCE10', '#E87C25', '#27727B',
                                '#FE8463', '#9BCA63', '#FAD860', '#F3A43B', '#60C0DD',
                                '#D7504B', '#C6E579', '#F4E001', '#F0805A', '#26C0C0'
                            ]
                            var color = colorList[params.dataIndex];//图例颜色
                            var htmlStr = '<div>';
                            htmlStr += params.seriesName + '<br/>';//x轴的名称
                            //为了保证和原来的效果一样，这里自己实现了一个点的效果
                            htmlStr += '<span style="margin-right:5px;display:inline-block;width:10px;height:10px;border-radius:5px;background-color:' + color + ';"></span>';
                            //添加一个汉字，这里你可以格式你的数字或者自定义文本内容
                            htmlStr += params.name + '：' + params.value + '';
                            htmlStr += '</div>';
                            return htmlStr;
                        }
                    },

                    grid: {
                        borderWidth: 0,
                        y2: 60,
                        right: '5%',
                        left: '5%',

                    },
                    xAxis: [
                        {
                            type: 'category',
                            show: true,
                            data: typeName,
                            axisLine: {
                                show: true,
                                lineStyle: {
                                    color: '#000',
                                }
                            },
                            splitLine: {
                                show: false
                            },
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value',
                            show: true,
                            axisLine: {
                                show: true,
                                lineStyle: {
                                    color: '#000',
                                }
                            },

                        }
                    ],
                    series: [
                        {
                            name: '客户订单状态统计',
                            type: 'bar',
                            itemStyle: {
                                normal: {
                                    color: function (params) {
                                        // build a color map as your need.
                                        var colorList = [
                                            '#C1232B', '#B5C334', '#FCCE10', '#E87C25', '#27727B',
                                            '#FE8463', '#9BCA63', '#FAD860', '#F3A43B', '#60C0DD',
                                            '#D7504B', '#C6E579', '#F4E001', '#F0805A', '#26C0C0'
                                        ]
                                        return colorList[params.dataIndex]
                                    },
                                    label: {
                                        show: true,
                                        position: 'top',
                                        formatter: '{b}\n{c}'
                                    }
                                }
                            },
                            "data": typeNum,
                            // markPoint: {
                            //     tooltip: {
                            //         trigger: 'item',
                            //         backgroundColor: 'rgba(0,0,0,0)',
                            //         formatter: function (params) {
                            //             return '<img src='
                            //                 + params.data.symbol.replace('image://', '')
                            //                 + '/>'
                            //         }
                            //     },
                            //     data: typeRatio
                            // }
                        }
                    ]

                }

                /!*var option = {
                    title: {
                        x: 'center'
                    },
                    /!*tooltip: {
                        trigger: 'item',
                        showDelay: 0,
                        formatter: function (params) {
                            var colorList = [
                                '#C1232B', '#B5C334', '#FCCE10', '#E87C25', '#27727B',
                                '#FE8463', '#9BCA63', '#FAD860', '#F3A43B', '#60C0DD',
                                '#D7504B', '#C6E579', '#F4E001', '#F0805A', '#26C0C0'
                            ]
                            var color = colorList[params.dataIndex];//图例颜色
                            var htmlStr = '<div>';
                            htmlStr += params.seriesName + '<br/>';//x轴的名称
                            //为了保证和原来的效果一样，这里自己实现了一个点的效果
                            htmlStr += '<span style="margin-right:5px;display:inline-block;width:10px;height:10px;border-radius:5px;background-color:' + color + ';"></span>';
                            //添加一个汉字，这里你可以格式你的数字或者自定义文本内容
                            htmlStr += params.name + '：' + params.value + '';
                            htmlStr += '</div>';
                            return htmlStr;
                        }
                    },*!/
                    tooltip : {
                        trigger: 'axis'
                    },
                    legend: {
                        data: legend
                    },
                    /!*legend: {
                        data: ['最高气温', '最低气温']
                    },*!/
                    toolbox: {
                        show : true,
                        feature : {
                            mark : {show: true},
                            dataView : {show: true, readOnly: false},
                            magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
                            restore : {show: true},
                            saveAsImage : {show: true}
                        }
                    },
                    calculable: true,
                    xAxis: [
                        {
                            type: 'category',
                            boundaryGap: false,
                            data: typeName
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value',
                            /!*axisLabel: {
                                formatter: '{value} °C'
                            },*!/
                        }
                    ],
                    /!*series: [
                        {
                            name: '产品订单状态统计',
                            type: 'line',
                            /!*data: [11, 11, 15, 13, 12, 13, 10],*!/
                            /!*markPoint: {
                                data: [
                                    {type: 'max', name: '最大值'},
                                    {type: 'min', name: '最小值'}
                                ]
                            },*!/
                            /!*markLine: {
                                data: [
                                    {type: 'average', name: '平均值'}
                                ]
                            }*!/
                            "data": typeNum,
                        },
                        /!*{
                            name: '最低气温',
                            type: 'line',
                            data: [1, -2, 2, 5, 3, 2, 0],
                            markPoint: {
                                data: [
                                    {name: '周最低', value: -2, xAxis: 1, yAxis: -1.5}
                                ]
                            },
                            markLine: {
                                data: [
                                    {type: 'average', name: '平均值'}
                                ]
                            }
                        }*!/
                    ]*!/
                    series:series
                };*!/
                // 为echarts对象加载数据
                myChart.setOption(option);

                window.onresize = myChart.resize;
            }
        );
    }*/


    //查出全部数据
    function personalData(timeType, timeVal, year, startTime, endTime, d2Id) {
        var data = {
            timeType: timeType ? timeType : '3',
        }
        if (startTime) {
            data.startTime = startTime;
        }

        if (endTime) {
            data.endTime = endTime;
        }

        if (d2Id) {
            data.d2Id = d2Id;
        }
        if (year) {
            data.timeType = 4;
            data.year = year;
        }

        //查出客户数据
        site.send({
            url: url.personalStatistic,
            data: data,
            callback: function (data) {
                data = JSON.parse(data)
                if (data.type == '1') {
                    data.content.timeVal = timeVal ? timeVal : '本季度';
                    var source = $("#personalData_list_tpl").html();
                    var template = Handlebars.compile(source);
                    var html = template(data.content);
                    $('#personalData_list').html(html);
                }
            }
        })

        //获取贷款类型
        site.send({
            url: url.loanTypeStatistic,
            data: data,
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == '1') {
                    loanTy(data.content);
                }
            }
        })

        //获取客户来源数据
        site.send({
            url: url.personalSourceStatistic,
            data: data,
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == '1') {
                    clientCom(data.content);
                }
            }
        })

        //获取申请期限
        site.send({
            url: url.applyTermStatistic,
            data: data,
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == '1') {
                    loanDl(data.content);
                }
            }
        })

        //获取客户地区
        site.send({
            url: url.personalCityStatistic,
            data: data,
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == '1') {
                    clientPosi(data.content);
                }
            }
        })


        //获取客户订单状态
        site.send({
            url: url.allPersonalOrderStateStatistic,
            data: data,
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == '1') {
                    $.each(data.content, function (e, i) {

                        var series = [];
                        var time = [];
                        var legend = [];

                        if(e % 2 === 0 || e === 0){
                            $("#echartsList").append('<div class="data-clientstate" style="width: 48%; float: left" id="echartList-' + e + '" _echarts_instance_="ec_15247945268' + e + '"\n' +
                                '                 style="-webkit-tap-highlight-color: transparent; user-select: none; position: relative; background: transparent;">\n' +
                                '                <div style="position: relative; overflow: hidden; width: 1280px; height: 396px; padding: 0px; margin: 0px; border-width: 0px; cursor: default;">\n' +
                                '                    <canvas width="1280" height="396" data-zr-dom-id="zr_0"\n' +
                                '                            style="position: absolute; left: 0px; top: 0px; width: 1280px; height: 396px; user-select: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); padding: 0px; margin: 0px; border-width: 0px;"></canvas>\n' +
                                '                </div>\n' +
                                '                <div></div>\n' +
                                '            </div>')
                        }else{
                            $("#echartsList").append('<div class="data-clientstate" style="width: 48%; float: right" id="echartList-' + e + '" _echarts_instance_="ec_15247945268' + e + '"\n' +
                                '                 style="-webkit-tap-highlight-color: transparent; user-select: none; position: relative; background: transparent;">\n' +
                                '                <div style="position: relative; overflow: hidden; width: 1280px; height: 396px; padding: 0px; margin: 0px; border-width: 0px; cursor: default;">\n' +
                                '                    <canvas width="1280" height="396" data-zr-dom-id="zr_0"\n' +
                                '                            style="position: absolute; left: 0px; top: 0px; width: 1280px; height: 396px; user-select: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); padding: 0px; margin: 0px; border-width: 0px;"></canvas>\n' +
                                '                </div>\n' +
                                '                <div></div>\n' +
                                '            </div>')
                        }



                        var lineData = [];
                        $.each(i, function (e, ii) {
                            lineData.push(ii.num);
                        })
                        /*// typeNameData.push(data.content.typeName)
                        typeNameData.push(ele.type_name)
                        typeNum.push(ele.type_num)
                        typeRatio.push({name: ele.typeRatio})*/
                        series.push({
                            name: i[0].product_name,
                            type: 'line',
                            data: lineData
                        })
                        legend.push(i[0].product_name);
                        $.each(data.content[0], function (ele, i) {
                            time.push(i.s_name);
                        })

                        seriesAll.push(series)
                        timeAll.push(time)
                        legendAll.push(legend)

                        echar_fun(e);

                    })


                    /*var typeName = [];
                    var typeRatio = [];
                    var typeNum = [];
                    $.each(data.content, function (i, e) {
                        typeName.push(e.type_name);
                        typeRatio.push(e.typeRatio);
                        typeNum.push(e.type_num);
                    })
                    bar_bottom(typeName, typeRatio, typeNum);*/
                }
            }
        })

        //获取客户订单
        site.send({
            url: url.personalOrderStateStatistic,
            data: data,
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == '1') {
                    clientOd(data.content)
                }
            }
        })
    }


    //初始化客户数据
    personalData();

    //今日，本月，本季度切换
    $('.client-pub > button').on('click', function () {
        $('.client-pub > button').addClass('btn-trans').removeClass('btn-blue')
        $(this).addClass('btn-blue').removeClass('btn-trans');
    })

    //搜索
    $('.sousuo').on('click', function () {
        personalData($('.btn-blue').data('time'), $('.btn-blue').text(), $("#year_list").val(), $('#startTime').val(), $('#endTime').val(), $('#department_list').val());
    })


    //年份选择，去除前面今日，本月，本季度的选中事件
    $('#year_list').on("change", function () {
        if ($(this).val()) {
            $('.client-pub > button').removeClass('btn-blue').addClass('btn-trans')
        } else {
            $('.client-pub > button:eq(2)').removeClass('btn-trans').addClass('btn-blue')
        }
    })

    //数据导出
    $("#export").on('click', function () {
        var data = {
            timeType: $('.client-pub .btn-blue').data('time') ? $('.client-pub .btn-blue').data('time') : 4
        }
        if ($("#year_list").val() && data.timeType === 4) {
            data.year = $("#year_list").val()
        }
        if ($("#department_list").val()) {
            data.d2Id = $("#department_list").val()
        }
        if ($("#startTime").val()) {
            data.startTime = $("#startTime").val()
        }
        if ($("#endTime").val()) {
            data.endTime = $("#endTime").val()
        }
        site.send({
            url: url.exportPersonalStatistic,
            data: data,
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == '1') {
                    //clientOd(data.content)
                    window.open(data.content);
                }
            }
        })
    })

    // 路径配置
    require.config({
        paths: {
            echarts: baseUrlStr + 'static/plugins/echarts'
        }
    });


    // 切换div
    $(".liec").each(function (i) {
        $("#echar6").css('display', 'none')

        $(this).click(function () {
            if (i == 0) {

                $("#echar1").css('display', 'block')
                $("#echar2").css('display', 'none')
                $("#echar3").css('display', 'none')
                $(this).css({"display": "block", "background": "rgb(41, 51, 92)", "color": "white"})
                $(".liec").eq(1).css({"background": "rgb(255, 255, 255)", "color": "black"})
                $(".liec").eq(2).css({"background": "rgb(255, 255, 255)", "color": "black"})

            }
            if (i == 1) {
                $("#echar1").css('display', 'none')
                $("#echar2").css('display', 'block')
                $("#echar3").css('display', 'none')
                $(this).css({"display": "block", "background": "rgb(41, 51, 92)", "color": "white"})
                $(".liec").eq(0).css({"background": "rgb(255, 255, 255)", "color": "black"})
                $(".liec").eq(2).css({"background": "rgb(255, 255, 255)", "color": "black"})
            }
            if (i == 2) {
                $("#echar1").css('display', 'none')
                $("#echar2").css('display', 'none')
                $("#echar3").css('display', 'block')
                $(this).css({"display": "block", "background": "rgb(41, 51, 92)", "color": "white"})
                $(".liec").eq(0).css({"background": "rgb(255, 255, 255)", "color": "black"})
                $(".liec").eq(1).css({"background": "rgb(255, 255, 255)", "color": "black"})
            }
            if (i == 3) {
                $("#echar6").css('display', 'none')
                $("#echar5").css('display', 'block')
                $(this).css({"display": "block", "background": "rgb(41, 51, 92)", "color": "white"})
                $(".liec").eq(4).css({"background": "rgb(255, 255, 255)", "color": "black"})
            }
            if (i == 4) {
                $("#echar5").css('display', 'none')
                $("#echar6").css('display', 'block')
                $(this).css({"display": "block", "background": "rgb(41, 51, 92)", "color": "white"})
                $(".liec").eq(3).css({"background": "rgb(255, 255, 255)", "color": "black"})
            }


        })

    })


    // 客户订单


        $(".datepicker").datepicker({
            format: 'yyyy-mm-dd',
            autoclose: true,
            pickerPosition: 'bottom',
        })

})